from __future__ import print_function

import grpc
import async_pb2
import async_pb2_grpc
import asyncio

CHANNEL_OPTIONS = [('grpc.lb_policy_name', 'pick_first'),
                   ('grpc.enable_retries', 0),
                   ('grpc.keepalive_timeout_ms', 10000)]

async def guide_get_feature(stub):
    point = async_pb2.Point(latitude=409146138, longitude=-746188906)
    feature = await stub.GetFeature(point)
    if not feature.location:
        print("Server returned incomplete feature")
        return
    if feature.name:
        print("Feature called %s at %s" % (feature.name, feature.location))
    else:
        print("Found no feature at %s" % feature.location)
    

async def main():
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    
    # with grpc.aio.insecure_channel('localhost:50051') as channel:
    async with grpc.aio.insecure_channel(target='localhost:50051',
                                         options=CHANNEL_OPTIONS) as channel:
        stub = async_pb2_grpc.RouteGuideStub(channel)
        print("-------------- GetFeature --------------")
        await guide_get_feature(stub)


if __name__ == '__main__':
    asyncio.run(main())
